package top.superflow.exception

import java.text.MessageFormat

import org.apache.commons.lang3.builder.ToStringBuilder
class RequestUnsupportedException (message: String, exception : Throwable) extends RuntimeException(message: String, exception : Throwable){


  def this(description : String){
    this(description, null.asInstanceOf[Throwable])
  }

  def this(request : Any){
    this(RequestUnsupportedException.printMessage(request))
  }

  def this(exception: Throwable, description : String, args : String* ){
    this(RequestUnsupportedException.printMessage(description, args : _*), exception)
  }


  def this(description: String, request : Any){
    this(RequestUnsupportedException.printMessage(description, request))
  }


  def this(description: String, args : String*){
    this(RequestUnsupportedException.printMessage(description, args : _*))
  }



}

object RequestUnsupportedException {

  private def printMessage (description : String, args : String*): String ={
    return MessageFormat.format(description, args)
  }

  private def printMessage (request : Any): String ={
    var obj : Object = null
    if(request != null){
      obj = request.asInstanceOf[Object]
    }

    return MessageFormat.format("The request {0} is not supported", obj)
  }

  private def printMessage (description:String, request : Any): String ={
    return MessageFormat.format(description, ToStringBuilder.reflectionToString(request))
  }
}